﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;
public partial class backstage_group_send_message : System.Web.UI.Page
{
    // Fields

    protected OutBox ob = new OutBox();
    protected OutBoxManager obm = new OutBoxManager();
    protected UserManager um = new UserManager();

    // Methods
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string pathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
        try
        {
            this.ob.Sender = "管理员";
            this.ob.Title = this.txtTitle.Value;
            this.ob.Content = this.txtaContent.Value;
            this.ob.LanguageVersion = this.Session["language_version"].ToString();
            ArrayList list = ArrayList.Adapter(base.Request.Form["addUser"].Split(new char[] { ',' }));
            foreach (string str2 in list)
            {
                this.ob.Addressee = str2;
                this.obm.SendEmail(this.ob);
            }
            base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"发送成功！\");location.href=\"out_box.aspx\";</script>");
        }
        catch
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"发送失败！\");</script>");
        }
    }

    public StringBuilder GetBcakLocation()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if (base.Request.QueryString["t"] == null)
            {
                return builder;
            }
            if (base.Request.QueryString["t"] == "ib")
            {
                builder.Append("location.href='in_box.aspx';");
                return builder;
            }
            builder.Append("location.href='out_box.aspx';");
        }
        catch
        {
        }
        return builder;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
    }

    protected StringBuilder UserBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            DataTable allUserEmailByLanguageVersion = this.um.GetAllUserEmailByLanguageVersion(this.Session["language_version"].ToString());
            foreach (DataRow row in allUserEmailByLanguageVersion.Rows)
            {
                builder.AppendLine("<option value=\"" + row["userName"].ToString() + "\">" + row["userName"].ToString() + "</option>");
            }
        }
        catch
        {
        }
        return builder;
    }

}